package com.firewolf.springcloud.service;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@Service
public class HelloService {
	@Autowired
	private RestTemplate restTemplate;

	@SuppressWarnings("unchecked")
	@HystrixCommand(fallbackMethod = "helloCallBack") //指定出错方法
	public Map<String, Object> hello() {
		return restTemplate.getForObject("http://micro-service/hello", Map.class);
	}

	// 错误的时候执行的函数
	public Map<String, Object> helloCallBack() {
		Map<String, Object> map = new HashMap<>();
		map.put("msg", "访问出错了....");
		return map;
	}
}
